import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'home.dart';
import 'tabs/tabs.dart';
import '../../widgets/widgets.dart';
import '../../shared/shared.dart';

class HomePage extends GetView<HomeLogic> {
  const HomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: Obx(() => _buildWidget()),
      onWillPop: () async => false,
    );
  }

  Stack _buildWidget() {
    return Stack(
      children: [
        const Background(imageURL: AssetsURL.backgroundPicture2, opacity: 0.60),
        Scaffold(
          backgroundColor: Colors.transparent,
          body: _buildContent(controller.state.currentTab.value),
          bottomNavigationBar: _bottomNavigationBar(),
        )
      ],
    );
  }

  BottomNavigationBar _bottomNavigationBar() {
    return BottomNavigationBar(
        items: [
          BottomNavigationBarItem(
              icon: IconFont(IconNames.messages, size: 35), label: '消息'),
          BottomNavigationBarItem(
              icon: IconFont(IconNames.newLogo, size: 75), label: '匹配'),
          BottomNavigationBarItem(
              icon: IconFont(IconNames.myself, size: 35), label: '我的'),
        ],
        showSelectedLabels: false,
        showUnselectedLabels: false,
        type: BottomNavigationBarType.fixed,
        backgroundColor: Colors.transparent,
        unselectedItemColor: ColorConstants.themeColor,
        currentIndex:
            controller.getCurrentIndex(controller.state.currentTab.value),
        selectedItemColor: ColorConstants.selectColor,
        onTap: (index) => controller.switchTab(index));
  }

  Widget _buildContent(MainTabs tab) {
    switch (tab) {
      case MainTabs.messages:
        return controller.state.messagesTab;
      case MainTabs.matching:
        return controller.state.matchingTab;
      case MainTabs.me:
        return controller.state.meTab;
      default:
        return controller.state.messagesTab;
    }
  }
}
